package com.oocl.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
	private static final String className = "oracle.jdbc.OracleDriver";		//ojdbc6.jar->oracle.jdbc->OracleDriver.Class
	private static final String url = "jdbc:oracle:thin:@ZHA-ITA077-w7:1521:ita3";//包装了oracle的�??议
	private static final String username = "jordan";
	private static final String psw = "123";	
	
	public static Connection createConnection(){
		Connection con = null;
		try {
			Class.forName(className);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			con = DriverManager.getConnection(url, username, psw);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return con;
	}
//	public static Connection createConnectionByJNDI(){
//		Connection con = null;
//		try {
//			InitialContext cxt = new InitialContext();
//			DataSource ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/myoracle" );
//			con = ds.getConnection();
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return con;
//	}
	public static void close(Connection con, PreparedStatement pst, ResultSet rs){
		if(rs!= null)
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		
		if(pst != null)
			try {
				pst.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		
		if(con != null)
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
	}
}
